// e_milliseconds.cpp
// GHD 06 Apr 2011
// Based on e_helloworld.cpp by RDB

#include "config.h" // BUILD directives include

#if BUILD_MILLISECONDS // Control compilation

#include "qec.h" // C++ base include for QE

// Holds number of frames and last time for loop completion
struct {
   float lastTime;
   int loopCount;
} Game;

int displayFrameCount()
{
   // Increase frame count
   Game.loopCount++;
   
   // Print frame count and elapsed time as integers 
   qePrintf("Frame: %d, Time: %d ms \n",
            Game.loopCount,
            (int)((qeTimeFrame() - Game.lastTime) * 1000));

   // Store last elasped time
   Game.lastTime = qeTimeFrame();
   return 0;
}

int qeMain(int argc,chr *argv[])
{
   bool isRunning = true;
   // Initialize Game struct
   Game.lastTime = 0;
   Game.loopCount = 0;

   // add a function object to engine
   if(!qeObjAddFnc(displayFrameCount))
   {
      BRK(); // error
      return 0;
   }

   // turn control over to the engine
   qeForever();
   
   return 0;
} // qeMain()

#endif